package org.myblog.myblogserver.code.controller;

import org.myblog.myblogserver.code.entity.Official;
import org.myblog.myblogserver.code.service.OfficialService;
import org.myblog.myblogserver.dao.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;

@Api(tags = "Official")
@RestController
@RequestMapping("/official")
public class OfficialController {

    @Autowired
    private OfficialService officialService;

    private Result  result = new Result();

    /**
     * get  /official/selectall<br/>
     *
     * @author 智哥
     * @return Result
     * */
    @ApiOperation(value = "Official查询全部")
    @GetMapping("/selectall")
    public Result selectall() {
        result.success("查询成功", officialService.list());
        return result;
    }


    /**
     * post  /official/insert<br/>
     * json <br/>
     *
     * @author 智哥
     * @param official
     * @return Result
     * */
    @ApiOperation(value = "Official添加")
    @PostMapping("/insert")
    public Result insert(@RequestBody Official official) {
        official.setId(null);
        if (officialService.save(official)){
            result.success("添加成功", true);
        }
        else{
            result.server_fail("添加失败", false);
        }
        return result;
    }


    /**
     * post  /official/deleteAll<br/>
     *
     * @author 智哥
     * @return Result
     * */
    @ApiOperation(value = "Official删除全部")
    @PostMapping("/deleteAll")
    public Result deleteAll() {
        if (officialService.remove(null)){
            result.success("删除成功", true);
        }
        else{
            result.server_fail("删除失败", false);
        }
        return result;
    }
}